package com.eqdd.yiqidian.ui.select;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.arlib.floatingsearchview.FloatingSearchView;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.SelectStaffActivityCustom;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.CareerListResultBean;
import com.eqdd.yiqidian.bean.rebuild.ListResultBean;
import com.eqdd.yiqidian.helper.mvchelper.ModelRx2DataSource;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.http.JsonConverter;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.shizhefei.mvc.MVCCoolHelper;

import org.reactivestreams.Publisher;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.functions.Function;

/**
 * 公司id(必传)
 * 部门id(非必传)
 * 选择职位返回,部门id不传,默认列出该公司所有职位
 */

public class SelectPostActivity extends BaseActivity {
    private RecyclerViewCustom dataBinding;
    private SlimAdapterEx<CareerListResultBean> slimAdapterEx;

    private int departId;
    private int comId;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "职位选择");
    }

    @Override
    public void initData() {
        comId = getIntent().getIntExtra(Config.COM_ID, 0);
        departId = getIntent().getIntExtra(Config.DEPARTMENT_ID, 0);
        dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        slimAdapterEx = SlimAdapterEx.create()
                .register(R.layout.list_item_01, new SlimInjector<CareerListResultBean>() {
                    @Override
                    public void onInject(CareerListResultBean data, IViewInjector injector) {
                        injector.text(R.id.tv_name, data.getName());
                    }
                })
                .attachTo(dataBinding.recyclerView).updateData(new ArrayList());
        ItemClickSupport.addTo(dataBinding.recyclerView)
                .setOnItemClickListener((recyclerView, position, v) -> {
                    Intent intent = new Intent();
                    intent.putExtra(Config.BEAN, (Serializable) slimAdapterEx.getDataItem(position));
                    setResult(Config.SUCCESS, intent);
                    finish();
                });

    }


    @Override
    public void setView() {
        OkGo.<HttpResult<List<CareerListResultBean>>>post(HttpConfig.BASE_URL + HttpConfig.SELECT_CAREER)
                .params("departId", departId)
                .params("companyId", comId)
                .execute(new DialogCallBack<HttpResult<List<CareerListResultBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpResult<List<CareerListResultBean>>> response) {
                        HttpResult<List<CareerListResultBean>> httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            slimAdapterEx.updateData(httpResult.getItems());
                        }
                    }
                });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }
}
